package com.bytedance.scenedemo.navigation.reuse;

import com.bytedance.scene.Scene;
import com.bytedance.scene.interfaces.PushOptions;
import com.bytedance.scene.ktx.SceneExtensions;
import com.bytedance.scenedemo.ResourceTable;
import com.bytedance.scenedemo.navigation.singletask.SingleTaskDemoScene1;
import com.bytedance.scenedemo.utility.ColorUtil;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;

/**
 * Created by JiangQi on 8/13/18.
 */
public class ReuseDemoScene extends Scene {
    @Override
    public Component onCreateView(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        Component layout=scatter.parse(ResourceTable.Layout_single_task_demo_scene,container,false);
        ScrollView svMain= (ScrollView) layout.findComponentById(ResourceTable.Id_sv_single_task_demo_scene_main);
        Text textHint= (Text) layout.findComponentById(ResourceTable.Id_text_single_task_demo_scene_hint);
        Text textPath= (Text) layout.findComponentById(ResourceTable.Id_text_single_task_demo_scene_path);
        Button btnGoTo= (Button) layout.findComponentById(ResourceTable.Id_btn_single_task_demo_scene_goto);

        svMain.setBackground(ColorUtil.getMaterialColor(0));
        textHint.setText(getClassName());
        textPath.setText("启动一个很重量级别的 Scene，onCreateView 耗时一秒，但是只有第一次会卡");

        btnGoTo.setText("启动");
        btnGoTo.setClickedListener(component -> {
            PushOptions options=new PushOptions.Builder()
                    .setRemovePredicate(new PushOptions.SingleTaskPredicate(ReuseScene1.class))
                    .build();
            SceneExtensions.getNavigationScene(this).push(ReuseScene1.class,null,options);
        });

        return layout;
    }
}
